package com.tanglongan.concurrent._basic;

import lombok.Getter;
import lombok.Setter;

public class Demo18 {
    public static void main(String[] args) throws InterruptedException {
        Demo18Thread t = new Demo18Thread();
        t.start();
        Thread.sleep(1000);

        t.suspend(); // 暂停线程运行
        System.out.println("A=" + System.currentTimeMillis() + ",i=" + t.getI());
        Thread.sleep(1000);
        System.out.println("A=" + System.currentTimeMillis() + ",i=" + t.getI());

        t.resume(); // 恢复线程运行
        Thread.sleep(1000);

        t.suspend();// 再次暂停线程运行
        System.out.println("B=" + System.currentTimeMillis() + ",i=" + t.getI());
        Thread.sleep(1000);
        System.out.println("B=" + System.currentTimeMillis() + ",i=" + t.getI());
    }
}

@Getter
@Setter
class Demo18Thread extends Thread {
    private long i = 0;

    @Override
    public void run() {
        while (true) {
            i++;
        }
    }
}